package cn.iot.controller.sys;

import cn.iot.common.dto.ResultMsg;
import cn.iot.sys.entity.SysRule;
import cn.iot.sys.service.SysRuleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.util.Map;

@RestController
@RequestMapping("/sys/rule")
public class SysRuleController {
    @Resource
    private SysRuleService sysRuleService;
    private Logger logger = LoggerFactory.getLogger(getClass());

    @PostMapping("addSysRule")
    public ResultMsg addSysRule(@RequestBody SysRule sysRule) throws UnsupportedEncodingException {
        logger.info("SysRuleController addSysRule sysRule{}",sysRule);
        ResultMsg msg = sysRuleService.addSysRule(sysRule);
        logger.debug("SysRuleController addSysRule msg{}",msg);
        return msg;
    }

    @PostMapping("getSysRuleList")
    public ResultMsg getSysRuleList(@RequestParam Map<String,Object> map){
        logger.info("SysRuleController getSysRuleList map{}",map);
        ResultMsg msg = sysRuleService.getSysRuleList(map);
        logger.debug("SysRuleController getSysRuleList msg{}",msg);
        return msg;
    }

    @PostMapping("delSysRuleById")
    public ResultMsg delSysRuleById(@RequestParam int id){
        logger.info("SysRuleController delSysRuleById id{}",id);
        ResultMsg msg = sysRuleService.delSysRuleById(id);
        logger.debug("SysRuleController delSysRuleById msg{}",msg);
        return msg;
    }

    @PostMapping("updSysRuleById")
    public ResultMsg updSysRuleById(@RequestBody SysRule sysRule){
        logger.info("SysRuleController updSysRuleById sysRule{}",sysRule);
//        ResultMsg msg = new ResultMsg();
        ResultMsg msg = sysRuleService.updSysRuleById(sysRule);
        logger.debug("SysRuleController updSysRuleById msg{}",msg);
        return msg;
    }
}
